package com.qaml.mes.device.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.earth.output.OutputMessage;
import com.earth.user.AuthSsoContext;
import com.qaml.mes.device.api.RbacClient;
import com.qaml.mes.device.dto.eqp.OrgIDReqDTO;
import com.qaml.mes.device.dto.eqp.OrgUserReqDTO;
import com.qaml.mes.device.vo.eqp.OrgRestVO;
import com.qaml.mes.device.vo.eqp.OrgUserVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName RbacController
 * @Description 组织用户信息
 * @Author leikai
 * @Date 2024/3/7 0007 9:20
 * @Version 1.0
 */
@RestController
@RequestMapping("/rbacClient")
public class RbacController {

    @Resource
    private RbacClient rbacClient;

    /**
     * 查询组织详情
     *
     * @param orgIDReqDTO
     * @return
     */
    @PostMapping("/org/detail")
    @ApiOperation(value = "查询组织详情", notes = "查询组织详情")
    public OutputMessage<OrgRestVO> orgDetail(@RequestBody OrgIDReqDTO orgIDReqDTO) {
        String currentUserToken = AuthSsoContext.getCurrentUserToken();
        JSONObject jsonObject = rbacClient.orgDetail(currentUserToken, orgIDReqDTO);
        OrgRestVO orgRestVO = JSON.parseObject(JSONObject.toJSONString(jsonObject.get("data")), OrgRestVO.class);
        return OutputMessage.success(orgRestVO);
    }

    /**
     * 查询组织用户列表
     *
     * @param orgIDReqDTO
     * @return
     */
    @PostMapping("/org/user")
    @ApiOperation(value = "查询组织用户列表", notes = "查询组织用户列表")
    public OutputMessage<List<OrgUserVO>> orgUser(@RequestBody OrgUserReqDTO orgIDReqDTO) {
        String currentUserToken = AuthSsoContext.getCurrentUserToken();
        JSONObject jsonObject = rbacClient.orgUser(currentUserToken, orgIDReqDTO);
        List<OrgUserVO> orgUserVOList = JSONObject.parseArray(JSON.toJSONString(jsonObject.get("itemList")), OrgUserVO.class);
        return OutputMessage.success(orgUserVOList);
    }
}